import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsEnum, IsNotEmpty, IsNumber, Min } from "class-validator";
import { DateDto } from "src/common/dto/dto";
import { FindOperator } from "typeorm";

export class GetCategoryDto extends DateDto {
    /** 分类名称 */
    @ApiPropertyOptional({
        type: String,
        name: 'categoryName',
        description: '分类名称',
    })
    public readonly categoryName: FindOperator<string>;
    /** 是否显示,0:否；1:是 */
    @ApiPropertyOptional({
        type: String,
        name: 'isShow',
        description: '是否显示,0:否；1:是',
        enum: [0, 1]
    })
    public readonly isShow?: string;
    /** 排序 */
    @ApiPropertyOptional({
        type: Number,
        name: 'sort',
        description: '排序',
        enum: [0, 1]
    })
    public readonly sort?: number;
}
export class CreateCategoryDto {
    /** 分类名称 */
    @IsNotEmpty({ message: '分类名称不能为空' })
    @ApiProperty({
        type: String,
        name: 'categoryName',
        description: '分类名称',
    })
    public readonly categoryName?: string;

    /** 是否显示,0:否；1:是 */
    @IsEnum([0, 1], { message: '只能传入0, 1' })
    @IsNotEmpty({ message: '是否显示,0:否；1:是' })
    @ApiProperty({
        type: String,
        name: 'isShow',
        description: '是否显示,0:否；1:是',
    })
    public readonly isShow?: string;

    /** 排序 */
    @IsNotEmpty({ message: '排序不能为空' })
    @IsNumber()
    @Min(0)
    @ApiProperty({
        type: Number,
        name: 'sort',
        description: '排序',
    })
    public readonly sort?: number;
}
export class UpdateCategoryDto extends CreateCategoryDto {
    @IsNotEmpty({ message: 'id不能为空' })
    @ApiProperty({
        type: Number,
        name: 'id',
        description: 'id',
    })
    public readonly id: number;
}